#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
int a[1101010];
void solve()
{
    memset(a, 0, sizeof -1);
    int n;
    cin >> n;

    for (int i = 1; i <= n-2; i++)
    {
        cin >> a[i];
    }

    for (int i = 1; i <= n -2 - 1 - 1; i++)
    {
        if (a[i] == 1 && a[i + 1] == 0 && a[i + 2] == 1)
        {
            no;
            return;
        }
    }
    yes;
    return;
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    // system("pause");
    return 0;
}
